﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAL;
using BLL;
namespace PhongMachTu.GUI
{
    public partial class frmThemBenhNhan : Form
    {
     
        public frmThemBenhNhan()
        {
            InitializeComponent();
        }
        public event EventHandler Button_Clicked;
        public int SoNguoi;
        public int soBenhNhanToiDa;
        KhambenhBLL bllKB = new KhambenhBLL();
        private void btnLuuVaThem_Click(object sender, EventArgs e)
        {
            if (SoNguoi <= soBenhNhanToiDa)
            {
                if (MsgBox.checkNull(txtTenBN))
                {
                    return;
                }
                if (MsgBox.checkNull(txtDiaChi))
                {
                    return;
                }
                BENHNHAN bn = new BENHNHAN();
                bn.HoTen = txtTenBN.Text;
                bn.NgaySinh = dtNgaySinh.Value;
                bn.DiaChi = txtDiaChi.Text;
                bn.GioiTinh = rbtNam.Checked ? true : false;
                BenhNhanBLL bllBN = new BenhNhanBLL();
                bllBN.ThemBenhNhan(bn);
                KHAMBENH kb = new KHAMBENH();
                kb.MaBenhNhan = bllBN.getID();
                kb.NgayKham = DateTime.Now;
                bllKB.ThemKhamBenh(kb);
                if (this.Button_Clicked != null)
                    this.Button_Clicked(sender, e);
            }
            else
            {
                MessageBox.Show("Quá 40 người không thể thêm!");

            }
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (SoNguoi <= soBenhNhanToiDa)
            {
                if (MsgBox.checkNull(txtTenBN))
                {
                    return;
                }
                if (MsgBox.checkNull(txtDiaChi))
                {
                    return;
                }
                BENHNHAN bn = new BENHNHAN();
                bn.HoTen = txtTenBN.Text;
                bn.NgaySinh = dtNgaySinh.Value;
                bn.DiaChi = txtDiaChi.Text;
                bn.GioiTinh = rbtNam.Checked ? true : false;
                BenhNhanBLL bllBN = new BenhNhanBLL();
                bllBN.ThemBenhNhan(bn);
                KHAMBENH kb = new KHAMBENH();
                kb.MaBenhNhan = bllBN.getID();
                kb.NgayKham = DateTime.Now;
                bllKB.ThemKhamBenh(kb);
                if (this.Button_Clicked != null)
                    this.Button_Clicked(sender, e);
                this.Close();
            }
            else
            {
                MessageBox.Show("Quá 40 người không thể thêm!");

            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmThemBenhNhan_Load(object sender, EventArgs e)
        {

        }
    }
}
